// 
// Decompiled by Procyon v0.5.36
// 

package com.cyberfend.cyfsecurity;

import java.util.concurrent.atomic.*;
import com.cyberfend.cyfsecurity.b.*;
import android.view.*;
import android.app.*;
import android.hardware.*;
import android.os.*;
import java.util.*;

final class h
{
    com.cyberfend.cyfsecurity.x a;
    com.cyberfend.cyfsecurity.k b;
    com.cyberfend.cyfsecurity.p c;
    com.cyberfend.cyfsecurity.ab d;
    private static final java.util.ArrayList<java.lang.Integer> f;
    private java.util.concurrent.atomic.AtomicBoolean g;
    boolean e;
    
    h() {
        this.a = null;
        this.b = null;
        this.c = null;
        this.d = null;
        this.g = new java.util.concurrent.atomic.AtomicBoolean(false);
        this.e = false;
    }
    
    final synchronized java.lang.String a() {
        com.cyberfend.cyfsecurity.b.a.a("Manager", "Getting sensor data", new java.lang.Throwable[0]);
        java.lang.String s = "default-mobile";
        try {
            if (this.b == null || this.c == null) {
                com.cyberfend.cyfsecurity.b.a.c("Manager", "AkamaiBMP SDK is not initialized", new java.lang.Throwable[0]);
                return s;
            }
            if (android.os.Looper.myLooper() == android.os.Looper.getMainLooper()) {
                s = this.b();
                this.c();
            }
            else {
                final android.os.Handler handler = new android.os.Handler(android.os.Looper.getMainLooper());
                final class a implements java.lang.Runnable
                {
                    public java.lang.String a;
                    
                    a() {
                        this.a = "default-mobile";
                    }
                    
                    @java.lang.Override
                    public final void run() {
                        try {
                            this.a = com.cyberfend.cyfsecurity.h.this.b();
                            com.cyberfend.cyfsecurity.h.this.c();
                        }
                        catch (java.lang.Exception ex) {
                            com.cyberfend.cyfsecurity.b.a.c("Manager", "Failed to get sensor data", ex);
                            com.cyberfend.cyfsecurity.f.a(ex);
                        }
                        synchronized (this) {
                            this.notify();
                        }
                    }
                }
                final com.cyberfend.cyfsecurity.h.a a2;
                final com.cyberfend.cyfsecurity.h.a a = a2 = new com.cyberfend.cyfsecurity.h.a();
                synchronized (a) {
                    handler.post((java.lang.Runnable)a2);
                    a2.wait();
                }
                s = a2.a;
            }
        }
        catch (java.lang.Exception ex) {
            com.cyberfend.cyfsecurity.b.a.c("Manager", "Failed to get sensor data", ex);
            com.cyberfend.cyfsecurity.f.a(ex);
        }
        return s;
    }
    
    final java.lang.String b() throws java.lang.Exception {
        com.cyberfend.cyfsecurity.b.a.a("Manager", "Building sensor data", new java.lang.Throwable[0]);
        final long uptimeMillis = android.os.SystemClock.uptimeMillis();
        if (com.cyberfend.cyfsecurity.e.o.equals("default_performance")) {
            com.cyberfend.cyfsecurity.e.o = com.cyberfend.cyfsecurity.q.a();
        }
        final java.lang.String l = com.cyberfend.cyfsecurity.e.l;
        final java.lang.String string = l + "," + com.cyberfend.cyfsecurity.u.a(l) + "," + java.lang.String.valueOf(new java.util.Random().nextInt()) + "," + java.lang.String.valueOf(com.cyberfend.cyfsecurity.d.a / 2L);
        final com.cyberfend.cyfsecurity.b.b<java.lang.String, java.lang.Long, java.lang.Long> b = this.c.b();
        final com.cyberfend.cyfsecurity.p c;
        (c = this.c).d = android.os.SystemClock.uptimeMillis();
        c.f.clear();
        c.g.clear();
        c.h.clear();
        c.c = 0L;
        final com.cyberfend.cyfsecurity.b.b<java.lang.String, java.lang.Long, java.lang.Long> b2 = this.b.b();
        final com.cyberfend.cyfsecurity.k b3;
        (b3 = this.b).d = android.os.SystemClock.uptimeMillis();
        b3.f.clear();
        b3.g.clear();
        b3.h.clear();
        b3.c = 0L;
        if (b.c < 10L && b2.c < 10L && com.cyberfend.cyfsecurity.ae.a().b != null) {
            final java.lang.String b4 = com.cyberfend.cyfsecurity.ae.a().b;
            if (this.g.compareAndSet(false, true)) {
                new java.util.Timer().schedule(new java.util.TimerTask() {
                    @java.lang.Override
                    public final void run() {
                        com.cyberfend.cyfsecurity.h.this.a();
                        g.compareAndSet(true, false);
                    }
                }, 3500L);
            }
            return b4;
        }
        final java.lang.String c2 = com.cyberfend.cyfsecurity.e.c;
        final java.lang.String a = com.cyberfend.cyfsecurity.e.a;
        final java.lang.String k = com.cyberfend.cyfsecurity.e.k;
        final java.lang.String n = com.cyberfend.cyfsecurity.e.n;
        java.lang.String s = "do_en";
        if (this.c.a.h) {
            s = "do_unr";
        }
        else if (!this.c.b) {
            s = "do_dis";
        }
        java.lang.String s2 = "dm_en";
        if (this.b.a.i) {
            s2 = "dm_unr";
        }
        else if (!this.b.b) {
            s2 = "dm_dis";
        }
        final java.lang.String string2 = s + "," + s2 + "," + "t_en";
        final long n2 = (android.os.SystemClock.uptimeMillis() - uptimeMillis) * 1000L;
        final long n3 = com.cyberfend.cyfsecurity.e.d + com.cyberfend.cyfsecurity.e.b + b.b + b2.b;
        final long n4 = java.lang.System.currentTimeMillis() - com.cyberfend.cyfsecurity.d.a;
        final java.lang.String string3 = com.cyberfend.cyfsecurity.e.d + "," + com.cyberfend.cyfsecurity.e.b + "," + (long)b.b + "," + (long)b2.b + "," + n3 + "," + n4 + "," + com.cyberfend.cyfsecurity.e.i + "," + com.cyberfend.cyfsecurity.e.j + "," + (long)b.c + "," + (long)b2.c + "," + com.cyberfend.cyfsecurity.d.p * 1000L + "," + n2 + "," + com.cyberfend.cyfsecurity.d.q + "," + com.cyberfend.cyfsecurity.a.a.a((long)(int)n3 << 32 | ((long)(int)(com.cyberfend.cyfsecurity.e.i + com.cyberfend.cyfsecurity.e.j + b.c + b2.c) & 0xFFFFFFFFL), (int)n4) + "," + com.cyberfend.cyfsecurity.d.a + ",0";
        final java.lang.String string4 = "2.1.2-1,2,-94,-100," + string + "-1,2,-94,-101," + string2 + "-1,2,-94,-105,-1,2,-94,-102," + k + "-1,2,-94,-108," + c2 + "-1,2,-94,-110,-1,2,-94,-117," + a + "-1,2,-94,-111," + b.a + "-1,2,-94,-109," + b2.a + "-1,2,-94,-112,-1,2,-94,-115," + string3 + "-1,2,-94,-106," + com.cyberfend.cyfsecurity.d.f + "," + com.cyberfend.cyfsecurity.d.g + "-1,2,-94,-70,-1,2,-94,-80,-1,2,-94,-120," + com.cyberfend.cyfsecurity.e.m + "-1,2,-94,-112," + com.cyberfend.cyfsecurity.e.o + "-1,2,-94,-121,-1,2,-94,-103," + n;
        new java.lang.StringBuilder("Sensor Data, Key Event size: ").append(c2.length());
        new java.lang.StringBuilder("Sensor Data, Touch Event size: ").append(a.length());
        new java.lang.StringBuilder("Sensor Data, Orientation Event size: ").append(b.a.length());
        new java.lang.StringBuilder("Sensor Data, Motion Event size: ").append(b2.a.length());
        new java.lang.StringBuilder("Sensor Data, Misc Stat size: ").append(string3.length());
        new java.lang.StringBuilder("Plain Sensor Data, Total size: ").append(string4.length());
        com.cyberfend.cyfsecurity.b.a.a("Manager", "Plain-BuildSensorData-Time: " + (android.os.SystemClock.uptimeMillis() - uptimeMillis) + "ms", new java.lang.Throwable[0]);
        final java.lang.String a2 = com.cyberfend.cyfsecurity.ad.a().a(string4);
        new java.lang.StringBuilder("Encrypted Sensor Data, Total size: ").append(a2.length());
        if (b.c >= 10L || b2.c >= 10L) {
            final com.cyberfend.cyfsecurity.ae a3 = com.cyberfend.cyfsecurity.ae.a();
            final java.lang.String b5 = a2;
            final com.cyberfend.cyfsecurity.ae ae = a3;
            a3.b = b5;
            new java.lang.Thread(new java.lang.Runnable() {
                @java.lang.Override
                public final void run() {
                    com.cyberfend.cyfsecurity.ae.b(com.cyberfend.cyfsecurity.ae.this);
                }
            }).start();
        }
        return a2;
    }
    
    final void c() {
        try {
            com.cyberfend.cyfsecurity.e.a();
            com.cyberfend.cyfsecurity.d.a();
            if (com.cyberfend.cyfsecurity.CYFMonitor.isActivityVisible()) {
                this.g();
                this.e();
                this.f();
                this.d();
            }
        }
        catch (java.lang.Exception ex) {
            new java.lang.StringBuilder("Exception occurred:").append(ex.getMessage());
            com.cyberfend.cyfsecurity.f.a(ex);
        }
    }
    
    static synchronized boolean a(final android.view.Window window) throws java.lang.Exception {
        final int hashCode = window.hashCode();
        for (int i = 0; i < com.cyberfend.cyfsecurity.h.f.size(); ++i) {
            if (hashCode == com.cyberfend.cyfsecurity.h.f.get(i)) {
                return true;
            }
        }
        com.cyberfend.cyfsecurity.h.f.add(hashCode);
        return false;
    }
    
    public final synchronized void a(final android.app.Application application) {
        try {
            if (this.c != null) {
                return;
            }
            this.c = new com.cyberfend.cyfsecurity.p();
            final com.cyberfend.cyfsecurity.p c = this.c;
            com.cyberfend.cyfsecurity.b.a.a("OrientationManager", "Initializing orientation manager", new java.lang.Throwable[0]);
            final com.cyberfend.cyfsecurity.p p = c;
            final com.cyberfend.cyfsecurity.p p2 = c;
            final long uptimeMillis = android.os.SystemClock.uptimeMillis();
            p2.e = uptimeMillis;
            p.d = uptimeMillis;
            c.a = new com.cyberfend.cyfsecurity.o(application);
        }
        catch (java.lang.Exception ex) {
            com.cyberfend.cyfsecurity.b.a.c("Manager", "Exception in creating orientation manager", ex);
            com.cyberfend.cyfsecurity.f.a(ex);
        }
    }
    
    public final void d() {
        try {
            final com.cyberfend.cyfsecurity.p c;
            if ((c = this.c).c < 300L) {
                final com.cyberfend.cyfsecurity.o a;
                final com.cyberfend.cyfsecurity.o o = a = c.a;
                o.b = o.a.getDefaultSensor(1);
                a.e = a.a.registerListener((android.hardware.SensorEventListener)a, a.b, 3);
                a.c = a.a.getDefaultSensor(2);
                a.f = a.a.registerListener((android.hardware.SensorEventListener)a, a.c, 3);
                if (android.os.Build$VERSION.SDK_INT >= 9) {
                    a.d = a.a.getDefaultSensor(9);
                    a.g = a.a.registerListener((android.hardware.SensorEventListener)a, a.d, 3);
                }
                if (a.g) {
                    a.a.unregisterListener((android.hardware.SensorEventListener)a, a.b);
                    a.e = false;
                    com.cyberfend.cyfsecurity.d.q = 1;
                }
                else {
                    com.cyberfend.cyfsecurity.d.q = 0;
                }
                a.i = android.os.SystemClock.uptimeMillis();
                boolean b;
                if ((a.e || a.g) && a.f) {
                    new java.lang.StringBuilder("orientation listener started with accelerometer ").append(a.e).append(" Gravity sensor ").append(a.g).append(" Magnetometer ").append(a.f);
                    b = true;
                }
                else {
                    com.cyberfend.cyfsecurity.b.a.c("OrientationListener", "Failed to register orientation listener", new java.lang.Throwable[0]);
                    a.a();
                    b = false;
                }
                if (!b) {
                    com.cyberfend.cyfsecurity.b.a.c("OrientationManager", "Orientation listener registration failed", new java.lang.Throwable[0]);
                    return;
                }
                c.b = true;
                c.a.addObserver(c);
            }
        }
        catch (java.lang.Exception ex) {
            com.cyberfend.cyfsecurity.b.a.c("Manager", "Exception in starting orientation manager", ex);
            com.cyberfend.cyfsecurity.f.a(ex);
        }
    }
    
    public final void e() {
        try {
            this.c.a();
        }
        catch (java.lang.Exception ex) {
            com.cyberfend.cyfsecurity.b.a.c("Manager", "Exception in stopping orientation manager", ex);
            com.cyberfend.cyfsecurity.f.a(ex);
        }
    }
    
    public final synchronized void b(final android.app.Application application) {
        try {
            if (this.b != null) {
                return;
            }
            this.b = new com.cyberfend.cyfsecurity.k();
            final com.cyberfend.cyfsecurity.k b = this.b;
            com.cyberfend.cyfsecurity.b.a.a("MotionManager", "Initializing motion manager", new java.lang.Throwable[0]);
            final com.cyberfend.cyfsecurity.k k = b;
            final com.cyberfend.cyfsecurity.k i = b;
            final long uptimeMillis = android.os.SystemClock.uptimeMillis();
            i.e = uptimeMillis;
            k.d = uptimeMillis;
            b.a = new com.cyberfend.cyfsecurity.j(application);
        }
        catch (java.lang.Exception ex) {
            com.cyberfend.cyfsecurity.b.a.c("Manager", "Exception in creating motion manager", ex);
            com.cyberfend.cyfsecurity.f.a(ex);
        }
    }
    
    public final void f() {
        try {
            final com.cyberfend.cyfsecurity.k b;
            if ((b = this.b).c < 300L) {
                final com.cyberfend.cyfsecurity.j a;
                final com.cyberfend.cyfsecurity.j j = a = b.a;
                j.b = j.a.getDefaultSensor(1);
                a.c = a.a.getDefaultSensor(4);
                a.e = a.a.registerListener((android.hardware.SensorEventListener)a, a.b, 3);
                a.f = a.a.registerListener((android.hardware.SensorEventListener)a, a.c, 3);
                com.cyberfend.cyfsecurity.b.a.a("MotionListener", "GyroScope status " + a.f + " and Accelerometer status " + a.e, new java.lang.Throwable[0]);
                boolean b2;
                if (!a.e && !a.f) {
                    com.cyberfend.cyfsecurity.b.a.c("MotionListener", "Failed to register motion listener", new java.lang.Throwable[0]);
                    a.a();
                    b2 = false;
                }
                else {
                    a.h = !a.e;
                    a.g = !a.f;
                    a.d = android.os.SystemClock.uptimeMillis();
                    a.j = (float)java.lang.System.nanoTime();
                    a.k = 0;
                    b2 = true;
                }
                if (!b2) {
                    com.cyberfend.cyfsecurity.b.a.c("MotionManager", "Motion listener registration failed", new java.lang.Throwable[0]);
                    return;
                }
                b.b = true;
                b.a.addObserver(b);
            }
        }
        catch (java.lang.Exception ex) {
            com.cyberfend.cyfsecurity.b.a.c("Manager", "Exception in starting motion manager", ex);
            com.cyberfend.cyfsecurity.f.a(ex);
        }
    }
    
    public final void g() {
        try {
            this.b.a();
        }
        catch (java.lang.Exception ex) {
            com.cyberfend.cyfsecurity.b.a.c("Manager", "Exception in stopping motion manager", ex);
            com.cyberfend.cyfsecurity.f.a(ex);
        }
    }
    
    static {
        f = new java.util.ArrayList<java.lang.Integer>();
    }
}
